﻿using System;
using System.Windows.Forms;
using ZYCommon;

namespace TextEditor
{
    

    public class A_InsertChar : A_Action
    {
        public override string ActionName()
        {
            return "insertchar";
        }

        public override bool CanHandleKeyDown()
        {
            return false;
        }

        public override A_Action Clone()
        {
            A_InsertChar ch = new A_InsertChar();
            ch.BaseCloneFrom(this);
            return ch;
        }

        public override bool Execute()
        {
            Keys k = base.KeyCode;
            if (k.ToString() == "12288")
                base.myOwnerDocument._InsertChar(' ');
            else
                base.myOwnerDocument._InsertChar((char)((ushort)k));
            return true;
        }

        public override bool isEnable()
        {
            return base.myOwnerDocument.CanModify();
        }

        public override bool TestHotKey(Keys vKeyCode, bool vShift, bool vControl, bool vAlt)
        {
            if ((vShift || vControl) || vAlt)
            {
                return false;
            }
            char c = (char) ((ushort) vKeyCode);
            if (char.IsControl(c))
            {
                return ((c == '\t') || (c == '\r'));
            }
            return true;
        }
    }
}

